﻿IF NOT EXISTS (
	SELECT 1
	FROM sys.columns 
	WHERE [object_id] = object_id(N'dbo.UDS_Mail') AND [name] = 'SMSFlag'
)
BEGIN
	/*
	 * SMSFlag:
	 *   0 - Don't send SMS
	 *   1 - Waiting for send
	 *   2 - Already sent
	 *   3 - Sent failed
	 */
	ALTER TABLE dbo.UDS_Mail ADD SMSFlag int NOT NULL CONSTRAINT [DF_UDS_Mail_SMSFlag] DEFAULT(0);
END
GO


/* Create an index on the column */
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE [object_id] = OBJECT_ID(N'dbo.UDS_Mail') AND name = N'IX_UDS_Mail_SMSFlag')
BEGIN
	CREATE NONCLUSTERED INDEX [IX_UDS_Mail_SMSFlag] ON [dbo].UDS_Mail ( SMSFlag ASC );
END
GO
